package fr.ants.view.panel;

import java.awt.Color;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.TransferHandler;

import fr.ants.controller.listener.ButtonsListener;
import fr.ants.view.Items;
import fr.ants.view.PictureManage;
import fr.ants.view.Selection;

public class NestButtonsPanel extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 2657738495868893436L;
	/**
	 * button to add a nest.
	 */
	private final JButton newNestButton;

	/**
	 * selection button.
	 */
	private final JButton selectionButton;

	/**
	 * Build.
	 * @param buttonsListener listener for the buttons
	 * @param transferHandler for the drag and drop
	 */
	public NestButtonsPanel(final ButtonsListener buttonsListener,
			final TransferHandler transferHandler) {
		// new nest
		newNestButton = new JButton(
				PictureManage.createIconToolBar(Items.NEW_NEST.getIcon()));
		newNestButton.setToolTipText(Items.NEW_NEST.getLabel());
		newNestButton.setAlignmentX(CENTER_ALIGNMENT);
		newNestButton.addMouseListener(buttonsListener);
		newNestButton.addMouseMotionListener(buttonsListener);
		newNestButton.setTransferHandler(transferHandler);
		newNestButton.setActionCommand(Items.NEW_NEST.getActionCommand());
		newNestButton.setEnabled(false);
		newNestButton.setBackground(Color.LIGHT_GRAY);
		add(newNestButton);

		// add the button selection
		selectionButton = new JButton(
				PictureManage.createIconToolBar(Items.SELECTION.getIcon()));
		selectionButton.setToolTipText(Items.SELECTION.getLabel());
		selectionButton.setActionCommand(Items.SELECTION.getActionCommand());
		selectionButton.addMouseListener(buttonsListener);
		selectionButton.setEnabled(false);
		selectionButton.setBackground(Color.GREEN);
		add(selectionButton);
	}

	/**
	 * to enable or not the buttons in the panel.
	 * @param b true to enable otherwise false
	 */
	public void setEnabledButtonNest(final boolean b) {
		newNestButton.setEnabled(b);
		selectionButton.setEnabled(b);
	}
	
	/**
	 * to see what mode is active
	 * 
	 * @param Selection sel
	 */
	
	public void activeButtons(Selection sel) {
		if(sel.equals(Selection.NEST)) {
			newNestButton.setBackground(Color.GREEN);
			selectionButton.setBackground(Color.LIGHT_GRAY);
		}
		
		else if(sel.equals(Selection.SELECTION) || sel.equals(Selection.CLICK_RIGHT)) {
			newNestButton.setBackground(Color.LIGHT_GRAY);
			selectionButton.setBackground(Color.GREEN);
		}
		else {
			newNestButton.setBackground(Color.LIGHT_GRAY);
			selectionButton.setBackground(Color.LIGHT_GRAY);			
		}
	}

}
